    //
//  ByNetUserApi.m
//  beibei_ios
//
//  Created by hebidu on 16/4/15.
//  Copyright © 2016年 hebidu. All rights reserved.
//

#import "ByNetUserApi.h"


@implementation ByNetUserApi

/** 登陆 */
+ (void)login:(ByNetParamsModel *)model
      success:(void(^)(ByNetBaseResult *result))success
      failure:(void(^)(ByNetBaseResult *result))failure {
        
    static NSString *apiType = @"BY_User_login";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%.0lf%d", [NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.username forKey:@"username"];
    [params setObject:model.password forKey:@"password"];
//    [params setObject:model.role forKey:@"role"];
    
    // 返回的responseObject 可能是字符串也可能是字典
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
                      
           UserLog(@"******** 登录 -> 成功: %@", responseObject);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"登录成功";
           ByNetUserModel *model = [[ByNetUserModel alloc] initContentWithDic:responseObject];
           result.data = model;
           result.notify_id = notifyID;

           if(success) {
               success(result);
           }

       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           UserLog(@"******** 登录 -> 失败: %@", error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
    
}

/** 注册 */
+ (void)reigster:(ByNetParamsModel *)model
         success:(void(^)(ByNetBaseResult *result))success
         failure:(void(^)(ByNetBaseResult *result))failure {
    
    static NSString *apiType = @"BY_User_register";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.username forKey:@"username"];
    [params setObject:model.password forKey:@"password"];
    [params setObject:model.reg_type forKey:@"reg_type"];
    [params setObject:model.from forKey:@"from"];
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           UserLog(@"******** 注册 -> 成功: %@", responseObject);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"注册成功";
           result.data = responseObject;
           result.notify_id = notifyID;

           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           UserLog(@"******** 注册 -> 失败: %@", error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
}

/** 用户资料更新 */
+ (void)updateUserInfo:(ByNetParamsModel *)model
               success:(void(^)(ByNetBaseResult *result))success
               failure:(void(^)(ByNetBaseResult *result))failure {
    
    static NSString *apiType = @"BY_User_update";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    // 必须参数
    [params setObject:model.uid forKey:@"uid"];
    if (model.nickname) {
        [params setObject:model.nickname forKey:@"nickname"];
    }
    if (model.realname) {
        [params setObject:model.realname forKey:@"realname"];
    }
    if (model.mobile) {
        [params setObject:model.mobile forKey:@"mobile"];
    }
    if (model.sex) {
        [params setObject:model.sex forKey:@"sex"];
    }
    if (model.qq) {
        [params setObject:model.qq forKey:@"qq"];
    }
    if (model.birthday) {
        [params setObject:model.birthday forKey:@"birthday"];
    }
    if (model.sign) {
        [params setObject:model.sign forKey:@"sign"];
    }
    if (model.email) {
        [params setObject:model.email forKey:@"email"];
    }
    
    // 返回的responseObject 可能是字符串也可能是字典
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeString
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
                      
           UserLog(@"******** 用户资料更新 -> 成功: %@", responseObject);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = responseObject;
           result.data = responseObject;
           result.notify_id = notifyID;

           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           UserLog(@"******** 用户资料更新 -> 失败: %@", error);

           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           NSDictionary *failInfoDic = @{@"-5" :@"邮箱格式不正确",
                                         @"-6" :@"邮箱长度不合法",
                                         @"-7" :@"邮箱禁止注册",
                                         @"-8" :@"邮箱被占用",
                                         @"-9" :@"手机格式不正确",
                                         @"-10":@"手机禁止注册",
                                         @"-11":@"手机号被占用",};
           NSString *errorMsg = nil;
           if ([failInfoDic.allKeys containsObject:error.domain]) {
               errorMsg = failInfoDic[error.domain];
           } else {
               errorMsg = @"未知错误";
           }
           result.msg = errorMsg;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
}

/** 头像上传 返回数据为字典 */
+ (void)iconUpload:(UIImage *)icon
           success:(void(^)(ByNetBaseResult *result))success
           failure:(void(^)(ByNetBaseResult *result))failure {
    
    [self uploadImage:icon type:@"avatar" success:^(NSArray *successAry) {
        NSDictionary *successDic = successAry[0];
        UserLog(@"******** 头像上传 -> 成功: %@", successDic);
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = 0;
        result.msg = @"头像上传成功";
        result.data = successDic; // 字典（头像相关信息，不是model，可取id，url，name等）
        
        if(success) {
            success(result);
        }
    } failure:^(NSURLSessionDataTask *operation, NSError *error) {
        UserLog(@"******** 头像上传 -> 失败: %@", error);
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = 0;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            [ByCoreToolAlert showFailureWithText:result.msg];
        }
    }];
}

/** 认证图片上传 */
+ (void)authenticationUpload:(UIImage *)icon
                     success:(void(^)(ByNetBaseResult *result))success
                     failure:(void(^)(ByNetBaseResult *result))failure {
    
    [self uploadImage:icon type:@"3" success:^(NSArray *successDic) {
        
        UserLog(@"******** 认证上传 -> 成功: %@", successDic);
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = 0;
        result.msg = @"上传成功";
        result.data = successDic; // 字典（头像相关信息，不是model，可取id，url，name等）
        
        if(success) {
            success(result);
        }
    } failure:^(NSURLSessionDataTask *operation, NSError *error) {
        UserLog(@"******** 认证上传 -> 失败: %@", error);
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = 0;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            [ByCoreToolAlert showFailureWithText:result.msg];
        }
    }];
}


/** 手机绑定 */
+ (void)boundMobilePhone:(ByNetParamsModel *)model
                 success:(void(^)(ByNetBaseResult *result))success
                 failure:(void(^)(ByNetBaseResult *result))failure {
    static NSString *apiType = @"BY_User_bind";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.uid forKey:@"uid"];
    [params setObject:model.password forKey:@"password"];
    [params setObject:model.code forKey:@"code"];
    [params setObject:model.mobile forKey:@"mobile"];
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeString
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           UserLog(@"******** 绑定手机 -> 成功: %@", responseObject);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"绑定手机成功";
           result.data = responseObject;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           UserLog(@"******** 绑定手机 -> 失败: %@", error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
    
}
/** 用手机找回密码 */
+ (void)retrievePwd:(ByNetParamsModel *)model
            success:(void(^)(ByNetBaseResult *result))success
            failure:(void(^)(ByNetBaseResult *result))failure {
    
    static NSString *apiType = @"BY_User_findPswByMobile";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.mobile forKey:@"mobile"];
    [params setObject:model.password forKey:@"psw"];

    // 返回的responseObject 可能是字符串也可能是字典
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeString
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           // 返回数据为 字符串
           NSAssert([responseObject isKindOfClass:[NSString class]], @"用手机找回密码 返回数据是字符串类型的，请检查");
           
           UserLog(@"******** 用手机找回密码 -> 成功: %@", responseObject);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = responseObject;
           result.data = responseObject;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           UserLog(@"******** 用手机找回密码 -> 失败: %@", error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
}




// 实名认证(一)
+ (void)realNameAttestation:(NSArray *)images
                    success:(void(^)(ByNetBaseResult *result))success
                    failure:(void(^)(ByNetBaseResult *result))failure {
    
    [self uploadImages:images type:@"ID" success:^(NSArray *successDic) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = 0;
        result.msg = @"照片已上传";
        result.data = successDic; // 字典（照片相关信息，不是model，可取id，url，name等）
        
        if(success) {
            success(result);
        }
        
    } failure:^(NSURLSessionDataTask *operation, NSError *error) {
        UserLog(@"******** 实名认证上传 -> 失败: %@", error);
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = 0;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            [ByCoreToolAlert showFailureWithText:result.msg];
        }
    }];
}
// 实名认证(第二步)
+ (void)realNameAttestationNext:(ByNetParamsModel *)model
                        success:(void(^)(ByNetBaseResult *result))success
                        failure:(void(^)(ByNetBaseResult *result))failure {
    static NSString *apiType = @"BY_User_verifyApply";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.uid forKey:@"uid"];
    [params setObject:model.realname forKey:@"realname"];
    [params setObject:model.idnumber forKey:@"idnumber"];
    [params setObject:model.bank_phone forKey:@"bank_phone"];
    [params setObject:model.bank_no forKey:@"bank_no"];
    // 返回的responseObject 可能是字符串也可能是字典
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeString
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           // 返回数据为 字符串
           NSAssert([responseObject isKindOfClass:[NSString class]], @"实名认证 返回数据是字符串类型的，请检查");
           
           UserLog(@"******** 实名认证 -> 成功: %@", responseObject);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = responseObject;
           result.data = responseObject;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           UserLog(@"******** 实名认证 -> 失败: %@", error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
}


///** 修改密码 */
//+ (void)modifyPwd:(ByNetUserModel *)model
//          success:(void(^)(ByNetBaseResult *result))success
//          failure:(void(^)(ByNetBaseResult *result))failure {
//    
//    static NSString *apiType = @"BY_User_updatePsw";
//    static NSInteger apiVersion = 100;
//    int rand = arc4random() % 1000;
//    
//    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
//    
//    // 拼接参数
//    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
//    [params setObject:model.uid forKey:@"uid"];
//    [params setObject:model.old_psw forKey:@"old_psw"];
//    [params setObject:model.password forKey:@"psw"];
//    
//    // 返回的responseObject 可能是字符串也可能是字典
//    [self post:requestId
//       apiType:apiType
//      dataType:ByNetDataTypeString
//     apiVerson:apiVersion
//        params:params
//       success:^(NSURLSessionDataTask *operation, id responseObject) {
//           
//           // 返回数据为 字符串
//           NSAssert([responseObject isKindOfClass:[NSString class]], @"修改密码 返回数据是字符串类型的，请检查");
//           
//           UserLog(@"******** 修改密码 -> 成功: %@", responseObject);
//           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
//           result.code = 0;
//           result.msg = responseObject;
//           result.data = responseObject;
//           
//           if(success) {
//               success(result);
//           }
//           
//       } failure:^(NSURLSessionDataTask *operation, NSError *error){
//           
//           UserLog(@"******** 修改密码 -> 失败: %@", error);
//           
//           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
//           result.code = error.code;
//           result.msg = error.domain;
//           result.data = error.localizedDescription;
//           if(failure) {
//               failure(result);
//           } else {
//               [ByCoreToolAlert showFailureWithText:result.msg];
//           }
//       }];
//}
//
///** 新手机绑定 */
//+ (void)bindMobile:(ByNetUserModel *)model
//           success:(void(^)(ByNetBaseResult *result))success
//           failure:(void(^)(ByNetBaseResult *result))failure {
//    
//    static NSString *apiType = @"BY_User_bind";
//    static NSInteger apiVersion = 100;
//    int rand = arc4random() % 1000;
//    
//    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
//    
//    // 拼接参数
//    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
//    [params setObject:model.uid forKey:@"uid"];
//    [params setObject:model.mobile forKey:@"mobile"];
//    [params setObject:model.code forKey:@"code"];
//    [params setObject:model.password forKey:@"password"];
//
//    // 返回的responseObject 可能是字符串也可能是字典
//    [self post:requestId
//       apiType:apiType
//      dataType:ByNetDataTypeString
//     apiVerson:apiVersion
//        params:params
//       success:^(NSURLSessionDataTask *operation, id responseObject) {
//           
//           // 返回数据为 字符串
//           NSAssert([responseObject isKindOfClass:[NSString class]], @"手机绑定 返回数据是字符串类型的，请检查");
//           
//           UserLog(@"******** 新手机绑定 -> 成功: %@", responseObject);
//           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
//           result.code = 0;
//           result.msg = responseObject;
//           result.data = responseObject;
//           
//           if(success) {
//               success(result);
//           }
//           
//       } failure:^(NSURLSessionDataTask *operation, NSError *error){
//           
//           UserLog(@"******** 新手机绑定 -> 失败: %@", error);
//           
//           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
//           result.code = error.code;
//           result.msg = error.domain;
//           result.data = error.localizedDescription;
//           if(failure) {
//               failure(result);
//           } else {
//               [ByCoreToolAlert showFailureWithText:result.msg];
//           }
//       }];
//}
//
//
///** 更换手机绑定 */
//+ (void)changeBindMobile:(ByNetUserModel *)model
//                 success:(void(^)(ByNetBaseResult *result))success
//                 failure:(void(^)(ByNetBaseResult *result))failure {
//    
//    static NSString *apiType = @"BY_User_changePhone";
//    static NSInteger apiVersion = 100;
//    int rand = arc4random() % 1000;
//    
//    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
//    
//    // 拼接参数
//    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
//    [params setObject:model.uid forKey:@"uid"];
//    [params setObject:model.mobile forKey:@"mobile"];
//    [params setObject:model.code forKey:@"code"];
//    [params setObject:model.password forKey:@"password"];
//    
//    // 返回的responseObject 可能是字符串也可能是字典
//    [self post:requestId
//       apiType:apiType
//      dataType:ByNetDataTypeString
//     apiVerson:apiVersion
//        params:params
//       success:^(NSURLSessionDataTask *operation, id responseObject) {
//           
//           // 返回数据为 字符串
//           NSAssert([responseObject isKindOfClass:[NSString class]], @"更换手机 返回数据是字符串类型的，请检查");
//           
//           UserLog(@"******** 更换手机绑定 -> 成功: %@", responseObject);
//           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
//           result.code = 0;
//           result.msg = responseObject;
//           result.data = responseObject;
//           
//           if(success) {
//               success(result);
//           }
//           
//       } failure:^(NSURLSessionDataTask *operation, NSError *error){
//           
//           UserLog(@"******** 更换手机绑定 -> 失败: %@", error);
//           
//           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
//           result.code = error.code;
//           result.msg = error.domain;
//           result.data = error.localizedDescription;
//           if(failure) {
//               failure(result);
//           } else {
//               [ByCoreToolAlert showFailureWithText:result.msg];
//           }
//       }];
//}
//
///** 手机验证登录 */
//+ (void)loginByMobile:(ByNetUserModel *)model
//              success:(void(^)(ByNetBaseResult *result))success
//              failure:(void(^)(ByNetBaseResult *result))failure {
//    
//    static NSString *apiType = @"BY_User_loginByCode";
//    static NSInteger apiVersion = 100;
//    int rand = arc4random() % 1000;
//    
//    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
//    
//    // 拼接参数
//    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
//    [params setObject:model.mobile forKey:@"mobile"];
//    [params setObject:model.code forKey:@"code"];
//    
//    // 返回的responseObject 可能是字符串也可能是字典
//    [self post:requestId
//       apiType:apiType
//      dataType:ByNetDataTypeDictionary
//     apiVerson:apiVersion
//        params:params
//       success:^(NSURLSessionDataTask *operation, id responseObject) {
//           
//           // 返回数据 字典
//           NSAssert([responseObject isKindOfClass:[NSDictionary class]], @"手机验证登陆 返回数据 应是字典类型的，请检查");
//           
//           UserLog(@"******** 手机验证登陆 -> 成功: %@", responseObject);
//           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
//           result.code = 0;
//           result.msg = @"请求成功";
//           if([responseObject isKindOfClass:[NSDictionary class]]) { // 是字典，则数据转化为model
//               ByNetUserModel *model = [[ByNetUserModel alloc] initContentWithDic:responseObject];
//               result.data = model;
//           } else { // 不是字典，则用字符串给数据赋值
//               result.data = responseObject;
//           }
//           if(success) {
//               success(result);
//           }
//           
//       } failure:^(NSURLSessionDataTask *operation, NSError *error){
//           
//           UserLog(@"******** 手机验证登陆 -> 失败: %@", error);
//           
//           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
//           result.code = error.code;
//           result.msg = error.domain;
//           result.data = error.localizedDescription;
//           if(failure) {
//               failure(result);
//           } else {
//               [ByCoreToolAlert showFailureWithText:result.msg];
//           }
//       }];
//    
//}
//
//



// 朱凯 add
// 用户信息
+ (void)getUserInfo:(ByNetParamsModel *)model
            success:(void(^)(ByNetBaseResult *result))success
            failure:(void(^)(ByNetBaseResult *result))failure {
    
    static NSString *apiType = @"BY_User_info";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.uid forKey:@"uid"];
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"获取用户信息成功";
           ByNetUserModel *model = [[ByNetUserModel alloc] initContentWithDic:responseObject];
           result.data = model;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           UserLog(@"******** 获取用户信息 -> 失败: %@", error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
    

}

// 用手机查用户信息
+ (void)getUserInfoWithMobile:(ByNetParamsModel *)model
                      success:(void(^)(ByNetBaseResult *result))success
                      failure:(void(^)(ByNetBaseResult *result))failure {
    
    static NSString *apiType = @"BY_User_infoByMobile";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.mobile forKey:@"mobile"];
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"获取用户信息成功";
           result.data = responseObject;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           UserLog(@"******** 获取用户信息 -> 失败: %@", error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
    
}
// 实名认证
+ (void)authenRealname:(ByNetParamsModel *)model
               success:(void(^)(ByNetBaseResult *result))success
               failure:(void(^)(ByNetBaseResult *result))failure {
    
    static NSString *apiType = @"BY_User_verify";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.uid forKey:@"uid"];
    [params setObject:model.realname forKey:@"realname"];
    [params setObject:model.idnumber forKey:@"idnumber"];
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeString
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"实名认证成功";
           result.data = responseObject;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           UserLog(@"******** 实名认证 -> 失败: %@", error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
}

// 经纪人名片认证
+ (void)authenAgentCard:(UIImage *)card
                success:(void(^)(ByNetBaseResult *result))success
                failure:(void(^)(ByNetBaseResult *result))failure {
    
    [self uploadImage:card type:@"broker" success:^(NSArray *successDic) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = 0;
        result.msg = @"名片已上传";
        result.data = successDic; // 字典（头像相关信息，不是model，可取id，url，name等）
        
        if(success) {
            success(result);
        }
        
    } failure:^(NSURLSessionDataTask *operation, NSError *error) {
        UserLog(@"******** 经纪人名片认证上传 -> 失败: %@", error);
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = 0;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            [ByCoreToolAlert showFailureWithText:result.msg];
        }
    }];
}



// 意见反馈
+ (void)feedback:(ByNetParamsModel *)model
         success:(void(^)(ByNetBaseResult *result))success
         failure:(void(^)(ByNetBaseResult *result))failure {
    static NSString *apiType = @"BY_User_suggest";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.uid forKey:@"uid"];
    [params setObject:model.mark forKey:@"content"];
  
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeString
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"意见反馈成功";
           result.data = responseObject;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           UserLog(@"******** 意见反馈 -> 失败: %@", error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];

}

@end
